/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package atrevaluator;

import java.util.ArrayList;
import java.util.HashSet;

/**
 *
 * @author iknoth
 */
public class JatrResultParser {

    private HashSet<TermItem> hashResults;
    private String filename;
    private ArrayList<TermItem> listResults;

    public JatrResultParser(String filename) {
        this.filename = filename;
        this.hashResults = new HashSet<TermItem>();
        this.listResults = new ArrayList<TermItem>();
    }
    
    public void parseFile() {
        
        InputOutput io = new InputOutput();
        ArrayList<String> resultsFileText = io.readFile(this.filename);  
        this.hashResults = new HashSet<TermItem>();
        this.listResults = new ArrayList<TermItem>();
        
        // adding to termItem resultsStructure
        for (String line : resultsFileText) {
            
            //System.out.println (line);
            
            String[] arr = line.split("\\|");
                                    
            ArrayList<String> variants = new ArrayList<String>();     
            
            for (int i = 0; i < (arr.length - 1); i ++) {
                //System.out.println("Adding " + arr[i]);
                variants.add(arr[i].trim().toLowerCase());
            }
            String[] arr2 = arr[arr.length - 1].split(" ");
            String last = "";
            for (int i = 0; i < (arr2.length - 1); i ++) {
                last += arr2 + " ";                
            }
            variants.add(last.trim());
            
            // do not add empty lines
            if (!variants.get(0).trim().equals("")) {
                this.hashResults.add(new TermItem(variants, new Double(arr2[arr2.length - 1])));
                this.listResults.add(new TermItem(variants, new Double(arr2[arr2.length - 1])));
            }            
        }      
    }       
    
    public HashSet<TermItem> getHashResults() {
        return this.hashResults;
    }
    
    public ArrayList<TermItem> getListResults() {
        return listResults;
    }
    
}
